package de.grosjohann.android.feuerwehr.panel;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import de.grosjohann.android.feuerwehr.R;

public class Panel {

  private final Context context;
  private final View layout;

  private final ImageView image;
  private final TextView text;

  public Panel(Context ctx, Activity act) {
    context = ctx;

    LayoutInflater inflater = act.getLayoutInflater();
    layout = inflater.inflate(R.layout.toast, (ViewGroup) act.findViewById(R.id.toastRoot));

    image = (ImageView) layout.findViewById(R.id.ivToast);
    text = (TextView) layout.findViewById(R.id.tvToast);
  }

  public void showInfo(int textId) {
    image.setImageResource(R.drawable.dlg_info);
    text.setText(textId);

    Toast toast = new Toast(context);
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();
  }

  public void showInfo(String msg) {
    image.setImageResource(R.drawable.dlg_info);
    text.setText(msg);

    Toast toast = new Toast(context);
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();
  }

  public void showWarning(String msg) {
    image.setImageResource(R.drawable.dlg_warning);
    text.setText(msg);

    Toast toast = new Toast(context);
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();
  }

  public void showError(int textId) {
    image.setImageResource(R.drawable.dlg_error);
    text.setText(textId);

    Toast toast = new Toast(context);
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();
  }

  public void showError(String msg) {
    image.setImageResource(R.drawable.dlg_error);
    text.setText(msg);

    Toast toast = new Toast(context);
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();
  }
}
